﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccessLayer;
using System.IO;

namespace WebApplication
{
    public partial class ForgetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='default.aspx'>Home</a> ><a href='Sign-In.aspx'>Sign In</a> ><span>Forget Password</span>";
        }

        protected void ForgetPassword_Click(object sender, EventArgs e)
        {
             string userName = txtUserName.Text.Trim();
                if (string.IsNullOrEmpty(userName))
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "Please enter valid Email ID";
                }
                else
                {
                    UesrList user = clsUser.ForgetPassword(userName);
                    if (null != user)
                    {
                       string MailContent =  File.ReadAllText(Server.MapPath("forgot_password.html"));
                       MailContent = MailContent.Replace("%%%%%%", userName);
                       MailContent  = MailContent.Replace("######", user.Password);
                       Utility.sendMail(userName, "Forget Password at RealStudio", MailContent);
                        Response.Redirect("Thanks.aspx");
                    }
                    else
                    {
                        lblMessage.Visible = true;
                        lblMessage.Text = "You are not registered user. Please check your Email ID.";
                    }
                }
        }
        protected void Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("Sign-In.aspx");
        }
        
    }
}